package day09.ExceptionTest;

import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        f();
    }

    private static void f() {
        System.out.println("输入两个浮点数:");
        double a = new Scanner(System.in).nextDouble();
        double b = new Scanner(System.in).nextDouble();
        try {
            double r = divide(a, b);
            System.out.println(r);
        }catch(ArithmeticException e){
            System.out.println("不能除0,是我们的错，请鞭笞我们把!");
            e.printStackTrace();
        }

    }

    private static double divide(double a, double b) {
        if(b == 0){
            ArithmeticException e = new ArithmeticException("/ by 0");
            //把异常对象抛回到调用位置
            throw e;
        }
        return a / b;
    }
}
